/**  
 * @Title: ccc.java
 * @Description: TODO(描述)
 * @author liuyi
 * @date 2023-11-24 15:01:48 
 */  
package com.fsxgt.datagrid.sys.utils;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;

import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;

import lombok.RequiredArgsConstructor;

/**  
 * @ClassName: ccc
 * @Description: TODO(描述)
 * @author liuyi
 * @date 2023-11-24 15:01:48 
*/
@Configuration
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class PageHelperInterceptorConfig implements BeanPostProcessor {
 
    private final List<SqlSessionFactory> sqlSessionFactories;
 
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof PageHelperAutoConfiguration) {
        	UserParametersInterceptor userParametersInterceptor = new UserParametersInterceptor();
            for (SqlSessionFactory sqlSessionFactory : sqlSessionFactories) {
                sqlSessionFactory.getConfiguration().addInterceptor(userParametersInterceptor);
            }
        }
        return bean;
    }
}
